package com.cs.study.homework._0205;

import java.util.Scanner;

public class Sum {
    public static void main(String[] args) {
        System.out.println("输入一个正整数：");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        //调佣isOdd方法输出结果
        System.out.println(num + "以内所有奇数的和是：" + isOdd(num));
    }

    //判断是否为奇数，并相加
    public static int isOdd(int num) {
        int sum = 0;
        for (int i = 0; i < num; i++) {
            if (i % 2 != 0) {
                sum += i;
            }
        }
        return sum;
    }
}
